﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using VNet.VisiSuite.Common.Resource;
using VNet.VisiSuite.VisiBoard.BusinessLogic;
using VNet.VisiSuite.VisiBoard.Common.Helpers;
using VNet.VisiSuite.VisiBoard.Dal.EntityClasses;

namespace VNet.VisiSuite.VisiBoard.Models
{
    public class DowntimeDialogModel : BaseModel
    {
        private static BusinessLogic.VisiBoard _visi_board = null;

        public DowntimeDialogModel()
        {
            _visi_board = BusinessLogic.VisiBoard.instance();
        }

        public IEnumerable<SimpleNode> ReasonCodes
        {
            get
            {
                var visi_board = BusinessLogic.VisiBoard.instance();
                return LocalUtil.reasonCodes(visi_board.AreaId, visi_board.DowntimeReasonId, false);
            }
        }

        /// <summary>
        /// Gets the break / lunch reason codes.
        /// </summary>
        /// <value>
        /// The break / lunch reason codes.
        /// </value>
        public IEnumerable<SimpleNode> BreakReasonCodes
        {
            get
            {
                var visi_board = BusinessLogic.VisiBoard.instance();
                return LocalUtil.BreakReasonCodes(visi_board.AreaId);
            }
        }

        public bool validateOperator(string operator_code, out string err_msg, out OperatorEntity op)
        {
            List<dynamic> ppc = _visi_board.currentAndNextProductionPlans();
            int pp_id = 0;
            if (ppc.Any() && ppc[0] != null)
                pp_id = ppc[0].ProductionPlanId;

            return _visi_board.validateOperator(operator_code, pp_id, out err_msg, out op);
        }
       
    }
}
